<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/5/8 0008
 * Time: 10:09
 */
header("Content-type:text/html;charset=utf-8");
session_start();
yzm();

function sjs($num){
    $str="1234567890";
    $list=array();
    $fil='';
    for($i=0;$i<$num;$i++){
        $rand=mt_rand(0,strlen($str)-1);
        $stat=$rand-$rand%3;
        $yzm=substr($str,$stat,1);
        $list[]=$yzm;
        $fil.=$yzm;
    }
    return $list;
}

function yzm(){
    $list=sjs(3);

    $img=imagecreatetruecolor(200,200);
    $bg=imagecolorallocate($img,200,200,200);
    imagefill($img,0,0,$bg);

    $nr='';
    foreach($list as $k=>$v){
        $bg2=imagecolorallocate($img,mt_rand(10,100),mt_rand(10,100),mt_rand(10,100));
        imagettftext($img,mt_rand(20,40),mt_rand(-40,40),30+30*($k+1),mt_rand(60,100),$bg2,'../public/home/qingshu.otf',$v);
        $nr.=$v;
    }

    if($_GET['type']=='zc'){
        $_SESSION['zc_yzm']=$nr;
    }elseif($_GET['type']=='dl'){
        $_SESSION['dl_yzm']=$nr;
    }

    header("Content-type:image/png"); //设置响应头，告诉浏览器这是图片

//4.输出
    imagepng($img);

//5.销毁
    imagedestroy($img);
}

?>